<template>
  <view class="category-list">
    <scroll-view 
      scroll-y 
      class="category-scroll"
    >
      <view 
        class="category-item" 
        v-for="item in categories" 
        :key="item.id"
        :class="{ active: activeId === item.id }"
        @click="selectCategory(item)"
      >
        <text>{{ item.name }}</text>
        <text class="count" v-if="item.productCount">({{ item.productCount }})</text>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  name: 'CategoryList',
  props: {
    categories: {
      type: Array,
      default: () => []
    },
    activeId: {
      type: [Number, String],
      default: ''
    }
  },
  methods: {
    selectCategory(category) {
      this.$emit('select', category)
    }
  }
}
</script>

<style lang="scss" scoped>
.category-list {
  height: 100%;
  background-color: #f5f5f5;
  
  .category-scroll {
    height: 100%;
  }
  
  .category-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100rpx;
    padding: 0 20rpx;
    background-color: #f5f5f5;
    position: relative;
    
    text {
      font-size: 28rpx;
      color: #666;
      text-align: center;
    }
    
    .count {
      font-size: 24rpx;
      color: #999;
      margin-left: 4rpx;
    }
    
    &.active {
      background-color: #ffffff;
      
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 6rpx;
        height: 36rpx;
        background-color: #ff5500;
        border-radius: 3rpx;
      }
      
      text {
        color: #333;
        font-weight: bold;
      }
    }
  }
}
</style> 